package speed2010.matcher.util;

import java.net.URI;

import speed2010.matcher.exceptions.InvalidOntologyFileException;
import speed2010.matcher.util.ontologyhelpers.OWLApiOntology;

public class FormatHelper {

	public static boolean isStringNumber(String number)
	{
		boolean isNumber = true;
		
		try
		{
			Double.parseDouble(number);
		}
		catch(Exception e)
		{
			isNumber = false;
		}
		
		return isNumber;
	}
	
	public static boolean isValidURI(String uri)
	{
		boolean isValid = true;
				
		try
		{
			URI.create(uri);
		}
		catch(Exception e)
		{
			isValid = false;
		}
		
		return isValid;
	}
	
	public static boolean isEmpty(String text)
	{
		boolean isEmpty = false;
		
		if(text == null || text.trim().length() == 0)
			isEmpty = true;
		
		return isEmpty;
	}
	
	public static boolean isValidOntologyFile(String filePath)
	{
		boolean isValid = true;
		
		try {
			new OWLApiOntology(filePath);
		} catch (InvalidOntologyFileException e) {
			isValid = false;
		}
		
		return isValid;
	}
	
	public static String formatFilePathToApi(String filePath, boolean removeSpaces)
	{
		String result = null;
		
		if(filePath != null)
		{
			result = "file:/" + replaceSlashs(filePath);
			
			if(removeSpaces)
				result = result.replace(" ", "%20");
		}		
		
		return result;
	}
	
	public static String formatFilePathToCMD(String filePath)
	{
		String result = null;
		
		if(filePath != null)
		{
			result = "file:///" + replaceSlashs(filePath).replace(" ", "%20");
		}
		
		return result;
	}
	
	public static String replaceSlashs(String filePath)
	{
		String result = null;
		
		if(filePath != null)
		{
			result = filePath.replace("\\", "/");
		}
		
		return result;
	}
}
